//
//  ClassifyTableViewDelegate.m
//  MyNewProject
//
//  Created by 王春辉 on 12/9/19.
//  Copyright © 2019 sun. All rights reserved.
//

#import "ClassifyTableViewDelegate.h"

@interface ClassifyTableViewDelegate() {
    NSIndexPath *_preSelectCellIndexPath;
}
@property (nonatomic, copy) ClassifyTableViewDidSelectRowAtIndexPathBlock block;
@end

static NSString *const identifier = @"tableView_cell_identifier";
@implementation ClassifyTableViewDelegate

#pragma mark -- mark UITableViewDelegate UITableViewDataSource
- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
    ClassifyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];
    cell.titleLabel.text = self.dataArray[indexPath.row];
    return cell;
}

- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if ([_preSelectCellIndexPath isEqual:indexPath]) {
        return; } // 防止重复点击
    _preSelectCellIndexPath = indexPath;
    if (self.block) { self.block(indexPath); }
}
#pragma mark -- mark UIScrollViewDelegate



#pragma mark -- mark 业务逻辑
/**
 cell点击事件回调
 
 @param block block
 */
- (void)didSelectRowAtIndexPathBlock:(ClassifyTableViewDidSelectRowAtIndexPathBlock)block {
    self.block = block;
}
@end
